﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class send_message_to_student : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string message = TextBox1.Text;
        string Sno = Request.QueryString["Sno"];
        string Cno = Request.QueryString["Cno"];

        string conn = "Data Source= . ;Initial Catalog=XSXK; User ID=sa; pwd=123";
        SqlConnection connection = new SqlConnection(conn);
        try
        {
            connection.Open();
            SqlCommand comm = new SqlCommand();
            comm.Connection = connection;

            string str_sql = " insert into message_to_student(Sno,Cno,message) values('" + Sno + "', '" + Cno + "', '" + message + "') ";
            comm.CommandText = str_sql;
            comm.ExecuteNonQuery();

            Response.Write("发送消息成功！");
        }
        catch (SqlException ex)
        {
            Response.Write(ex.Message);
        }

        finally
        {
            connection.Close();//关闭数据库连接
        }
    }
}